/*
 *  Copyright (C) 2012 Компания ВИТ. web: http://diasled.ru Е-mail:  vit@diasled.ru
 * 
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 * 
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 * 
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 * 
 */
package ru.apertum.diasled.cfg;

import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
import java.util.Comparator;
import java.util.LinkedList;

/**
 * Контур. Контур состоит из последовательности узлов, определяющихся координатами.
 * Контур финалезирован если координаты первого и последнего узлов совпадают.
 * @author Evgeniy Egorov
 */
public final class Outline implements Comparator<Outline>, Comparable<Outline> {

    public Outline() {
    }
    /**
     * Последовательность узлов контура
     */
    @Expose
    @SerializedName("outline")
    private LinkedList<MyPoint> route = new LinkedList<>();

    public LinkedList<MyPoint> getRoute() {
        return route;
    }

    public void setList(LinkedList<MyPoint> route) {
        this.route = route;
    }

    @Override
    public String toString() {
        return "Контур " + route.size() + " узлов";
    }
    /**
     * Зоны контура
     */
    @Expose
    @SerializedName("zone")
    private LinkedList<Zone> zone = new LinkedList<>();

    public LinkedList<Zone> getZone() {
        return zone;
    }

    public void setZone(LinkedList<Zone> zone) {
        this.zone = zone;
    }

    @Override
    public int compare(Outline o1, Outline o2) {
        if (o1.getRoute().size() != o2.getRoute().size()) {
            return -1;
        }
        for (int i = 0; i < o1.getRoute().size(); i++) {
            if (!o1.getRoute().get(i).equals(o2.getRoute().get(i))) {
                return -1;
            }
        }
        return 0;
    }

    @Override
    public int compareTo(Outline o) {
        if (getRoute().size() != o.getRoute().size()) {
            return -1;
        }
        for (int i = 0; i < getRoute().size(); i++) {
            if (!getRoute().get(i).equals(o.getRoute().get(i))) {
                return -1;
            }
        }
        return 0;
    }
}
